<%@ page language="java" import="java.util.*" import="java.sql.*" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ page import="com.example.demo2.DBUtil" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>后台管理系统</title>
</head>
<link rel="stylesheet" href="css/bootstrap.css">
<body>
<style>
    .center{display: flex !important;align-content: center;justify-content: center;align-items: center;}
</style>
<div style="display: flex; justify-content: center;flex-direction: column;align-items: center;">
    <%@include file="admin_header.jsp"%>
    <div style="margin-top: 20px">

        <ul class="list-group list-group-horizontal">
            <li class="list-group-item" style="width: 50px">ID</li>
            <li class="list-group-item"style="width: 150px">用户名</li>
            <li class="list-group-item"style="width: 150px">电影名称</li>
            <li class="list-group-item"style="width: 150px">电影院名称</li>
            <li class="list-group-item"style="width: 150px">所在厅</li>
            <li class="list-group-item"style="width: 150px">付款金额</li>
            <li class="list-group-item"style="width: 150px">操作</li>
        </ul>
        <%
            request.setCharacterEncoding("UTF-8");
            String a_name = request.getParameter("a_name");
            String a_pinp = request.getParameter("a_pinp");
            String a_xzq = request.getParameter("a_xzq");
            String a_leix = request.getParameter("a_leix");
            String a_fuw = request.getParameter("a_fuw");
            String a_jvli = request.getParameter("a_jvli");
            String a_qian = request.getParameter("a_qian");
            String a_dizhi = request.getParameter("a_dizhi");
            String a_phone = request.getParameter("a_phone");

            String u_id = request.getParameter("u_id");
            String u_name = request.getParameter("u_name");
            String u_pinp = request.getParameter("u_pinp");
            String u_xzq = request.getParameter("u_xzq");
            String u_leix = request.getParameter("u_leix");
            String u_fuw = request.getParameter("u_fuw");
            String u_jvli = request.getParameter("u_jvli");
            String u_qian = request.getParameter("u_qian");
            String u_dizhi = request.getParameter("u_dizhi");
            String u_phone = request.getParameter("u_phone");
            String d_id = request.getParameter("d_id");
            Connection cn = null;
            PreparedStatement ps = null;

            ResultSet rs = null;
            String sql = "";
            cn = DBUtil.getConnection();
            sql = "SELECT d.id, u.user as u_user,g.name as g_name,f.name as f_name,c.name as c_name,f.qian from" +
                    " dyp_dd d JOIN user u on d.u_id = u.id JOIN goods g on d.g_id = g.id " +
                    "JOIN fyt f on d.f_id = f.id JOIN cinema c on f.c_id = c.id";
            ps = cn.prepareStatement(sql);
            rs = ps.executeQuery();

            String error = "";
//            System.out.println(a_name);
            if (a_name != null && a_pinp !=null){
                int n=0;
                sql = "insert into cinema(name,pinp,xzq,leix,fuw,jvli,qian,dizhi,phone) values(?,?,?,?,?,?,?,?,?)";
                ps = cn.prepareStatement(sql);
                ps.setObject(1, a_name);
                ps.setObject(2, a_pinp);
                ps.setObject(3, a_xzq);
                ps.setObject(4, a_leix);
                ps.setObject(5, a_fuw);
                ps.setObject(6, a_jvli);
                ps.setObject(7, a_qian);
                ps.setObject(8, a_dizhi);
                ps.setObject(9, a_phone);
                n= ps.executeUpdate();
                response.sendRedirect("ad_dindan.jsp");
            }
            if (u_id != null){
                int n=0;
                sql = sql = "UPDATE cinema SET name =\""+u_name+"\", pinp =\""+ u_pinp +"\" "+ ",xzq=\"" + u_xzq + "\",leix=\"" + u_leix +
                        "\",fuw=\""+ u_fuw + "\",jvli=\"" + u_jvli + "\",qian=" + u_qian + ",dizhi=\"" + u_dizhi +
                        "\",phone=\"" + u_phone + "\" WHERE id=" + u_id;
                System.out.println(sql);
                ps = cn.prepareStatement(sql);
                n= ps.executeUpdate();
                response.sendRedirect("ad_xitong.jsp");

            }
//
            if (d_id != null){
                int n=0;
                sql = "DELETE FROM `gp`.`dyp_dd` WHERE `id` = " + d_id;
//              System.out.println(sql);
                ps = cn.prepareStatement(sql);
                n= ps.executeUpdate();
                response.sendRedirect("ad_dindan.jsp");
            }
            while(rs.next()){
                int id = rs.getInt("id");
                String u_user = rs.getString("u_user");
                String g_name = rs.getString("g_name");
                String f_name = rs.getString("f_name");
                String c_name = rs.getString("c_name");
                String qian = rs.getString("qian");
        %>
        <ul class="list-group list-group-horizontal-sm">
            <li class="list-group-item center"style="width: 50px;"><%=id%></li>
            <li class="list-group-item center"style="width: 150px"><%=u_user%></li>
            <li class="list-group-item center"style="width: 150px"><%=g_name%></li>
            <li class="list-group-item center"style="width: 150px"><%=c_name%></li>
            <li class="list-group-item center"style="width: 150px"><%=f_name%></li>
            <li class="list-group-item center"style="width: 150px"><%=qian%></li>
            <li class="list-group-item center"style="width: 150px">
                <a href="ad_dindan.jsp?d_id=<%=id%>" type="button" class="btn btn-info btn-sm" style="margin-bottom: 20px">退票</a>
            </li>
        </ul>

        <%
            }
        %>
    </div>

</div>
<script src="js/jQuery.js"></script>
<script src="js/bootstrap.js"></script>

</body>
</html>